package pl.wr.particle.impl;

import pl.wr.core.IObjectProperties;
import pl.wr.particle.ParticleProperties;
import pl.wr.particle.def.matter.IParticle;
import pl.wr.particle.impl.quantum.PhysicalSpace;

/**
 * Cząstka
 *
 * @version 1.0
 * @author wieslaw.rodak
 *
 */
public abstract class Particle implements IParticle {

	public boolean validateParticle() {
		return parentParticle.validateParticle();
	}

	/**
	 * właściwości cząstki
	 */
	private ParticleProperties properties;
	
	/**
	 * lokalizacja w przestrzeni
	 */
	private int positionInSpace;
	
	/**
	 * subcząstki z których jest zbudowana
	 */
	protected IParticle[] carringParticles;
	
	/**
	 * cząstka do której należy
	 * TODO zamienić na cząstkę lub cząsteczkę
	 */
	private IParticle parentParticle;

	
	protected Particle() {
		properties = new ParticleProperties();
	}
	
	protected Particle(IParticle ... carringParticles) {
		this();
		this.carringParticles = carringParticles;
	}
	

	public ParticleProperties getProperties() {
		return properties;
	}

	public void setProperties(IObjectProperties properties) {
		this.properties = (ParticleProperties) properties;
	}
	
	public void addToSpace(){
		final IParticle[] particle = {this};
		positionInSpace = PhysicalSpace.getSpace().addParticles(particle);
	}
	
	public void removeFromSpace(){
		PhysicalSpace.getSpace().getParticles()[positionInSpace] = null;
	}

	public int getPositionInSpace() {
		return positionInSpace;
	}

	public IParticle getParentParticle() {
		return parentParticle;
	}

	public void setParentParticle(IParticle parentParticle) {
		this.parentParticle = parentParticle;
	}

    public IParticle[] getCarringParticles() {
        return carringParticles;
    }
	
}
